package com.kn

class GroupAccount {
    List accounts
    static hasMany = [ accounts:com.kn.Accnt ]
    String name
//    BigDecimal groupAccountValue = 0.00
//    BigDecimal groupFee = 0.00
    def com.kn.RateSchedule rateSchedule;
    boolean invoiced = false;
    String salutation
    String address1
    String address2
    String city
    String state
    String zip
    String phone1
    String phone2

    static constraints = {
        name(unique: true, blank:false, maxSize:50)
        accounts(nullable:true)
        rateSchedule(nullable:true)
        invoiced()
    salutation(nullable:true)
    address1(nullable:true)
    address2(nullable:true)
    city(nullable:true)
    state(nullable:true)
    zip(nullable:true)
    phone1(nullable:true)
    phone2(nullable:true)


        }

    String toString() {
        "${this.name}"
    }

    def String buildAddress() {
        String addyStr = ""
        if(this.salutation != null && this.salutation.length() > 0) {
            addyStr += "${this.salutation}<br>"
        } else {
            addyStr += "${this.name}<br>"
        }
        if(this.address1) {
            addyStr += "${this.address1}<br>"
        }
        if(this.address2) {
            addyStr += "${this.address2}<br>"
        }
        if(this.city != null && this.city.length() > 0) {
            addyStr += "${this.city ?: ""}, ${this.state?: ""} ${this.zip?: ""}"
        } else {
            addyStr += "${this.state?: ""} ${this.zip?: ""}"
        }

        return addyStr
    }
}
